package filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CommonFilter implements Filter{

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest rq=(HttpServletRequest)request;
		HttpServletResponse rp=(HttpServletResponse)response;
		HttpSession session=rq.getSession();
		String path=rq.getRequestURI();
		//String base=path.toString();
		if(path.equals("/order/login.jsp")||path.equals("/order/action/managerlogin.jsp")||path.startsWith("/order/website")||path.startsWith("/order/action/websiteAction")){
			chain.doFilter(request, response);
		}
		else{
			String name=(String)session.getAttribute("name");
			if(name==null){
				rp.sendRedirect("/order/login.jsp");
			}else{
				chain.doFilter(request, response);
			}
		}
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
